
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jl_plugin/bean/BlueDevice.dart';
import 'package:jl_plugin/callback/BtRcspCallBack.dart';
import 'package:jl_plugin/jl_plugin.dart';
import 'package:jl_plugin/contain/StateCode.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:jl_plugin_example/BlueScanList.dart';
import 'BluetoothHelper.dart';

class HomePage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _State();
  }

}

class _State extends State<HomePage> {
  var initResult=false;

  @override
  void initState() {
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: [
          Container(
            width: double.infinity,
            child: TextButton(onPressed: () async{
              BluetoothHelper.startScan();
            }, child: Text("打开蓝牙权限")),
          ),
          SizedBox(height: 8),
          Container(
            width: double.infinity,
            child: TextButton(onPressed: () async{
              var result= await JlPlugin.instance.initSdk({});
              setState(() {
                initResult=result ??false;
              });
            }, child: Text(initResult==false?"初始化SDK":"初始化成功")),
          ),
          SizedBox(height: 8),
          Container(
            width: double.infinity,
            child: TextButton(onPressed: (){
              if(initResult){
                Navigator.push(context, MaterialPageRoute(builder: (context)=>BlueScanListPage()));
              }else{
                SmartDialog.showToast("请先初始化SDK");
              }
            }, child: Text("蓝牙搜索")),
          )
        ],
      ),
    );
  }

}